/*
 * @Descripttion: 
 * @version: 1.0.0
 * @Author: shuaishuai.han
 * @Date: 2022-03-24 09:56:46
 */
const {
  publicPath, devServer
} = require('./config');
const { chainWebpackNoConsole, chainSvgRuleConfig } = require('./config/plugin');

const chainWebpackGloablConfig = (config) => {
  config.plugin('html').tap((args) => {
    args[0].title = '';
    return args;
  });
}

module.exports = {
  publicPath,
  devServer,
  productionSourceMap: false,
  chainWebpack: config => {
    // 移除prefetch插件，避免加载多余的资源
    config.plugins.delete('prefetch');
    // 移除 preload 插件，避免加载多余的资源
    config.plugins.delete('preload');
    config.optimization.splitChunks({
      chunks: 'all'
    });
    chainWebpackGloablConfig(config);
    // 图片压缩
    // chainWebpackImg(config);
    // 生产环境去除console
    chainWebpackNoConsole(config);
    // svg
    chainSvgRuleConfig(config);
  },
  css: {
    loaderOptions: {
      sass: {
        prependData: `
        @import "@/styles/variables.scss";
        `,
      }
    },
  },
  configureWebpack: {
    // devtool: 'none',
    devtool: 'source-map',
    resolve: {
      extensions: ['.js', '.json', '.sass', '.css', '.vue'],
    },
  },
};
